/*************************************************************************
	> File Name: Command.cc
	> Author: Joker
	> Mail: mahongtao@foxmail.com 
	> Created Time: 2020-09-22 14:27:29
 ************************************************************************/

#include "Command.h"

#include <iostream>

using std::cout;
using std::endl;

void Receiver::Action(){
    cout << "Receiver Action" << endl;
}

Invoker::Invoker(Command * pCommand)
    :_pCommand(pCommand)
{
    cout << "Invoker(Command *)" << endl;
}

Invoker::~Invoker(){
    cout << "~Invoker()" << endl;

    delete _pCommand;
    _pCommand = nullptr;
}

void Invoker::Invoke(){
    if(nullptr != _pCommand){
        _pCommand->Execute();
    }
}

ConcreateCommand::ConcreateCommand(Receiver * pReceiver)
    :_pReceiver(pReceiver)
{
    cout << "ConcreateCommand(Receiver *)" << endl;
}

ConcreateCommand::~ConcreateCommand(){
    cout << "~ConcreateCommand()" << endl;

    delete _pReceiver;
    _pReceiver = nullptr;
}

void ConcreateCommand::Execute(){
    if(nullptr != _pReceiver){
        _pReceiver->Action();
    }

    cout << "Execute by ConcreateCommand" << endl;
}
